<?php
/**
 * KvFramework action base class
 * @package KvFramework_v2
 * @subpackage KvF_ModuleHandler
 * @author Greg McWhirter <gsmcwhirter@gmail.com>
 * @copyright Copyright &copy; 2006, Greg McWhirter
 * @version $Revision$
 */

/**
 * Action base class
 * @package KvFramework_v2
 * @subpackage KvF_ModuleHandler
 */
abstract class KvfAction extends KvfBase implements KvfActionInterface
{
  /**
   * Holds a reference to the parent module
   *
   * @var KvfModule
   */
  protected $_parent;

  /**
   * Flag for if the flow has been redirected
   *
   * @var boolean
   */
  protected $_redirected = false;

  /**
   * The request method for the current action
   *
   * @var string
   */
  protected $_RequestMethod;

  /**
   * Constructor
   *
   * @param KvfModule $_parent
   * @param string $_rm The request method
   * @throws KvfModuleException
   */
  public function __construct(KvfModule &$_parent, $_rm)
  {
    $this->_parent = $_parent;

    if (!in_array($_rm, array("GET","POST")))
    {
      throw new KvfModuleException("Request method ".$_rm." was not understood.", KvfModuleException::UnknownRequestMethod);
    }
    $this->_RequestMethod = strtoupper($_rm);


  }

  /**
   * Validate some data
   * @throws KvfModuleException
   */
  public function Validate()
  { }

  /**
   * Process data
   * @throws KvfModuleException
   */
  public function Process()
  { }

  /**
   * Display something
   *
   */
  public function Display()
  { }

  /**
   * Handle an error being thrown
   *
   * @param integer $_ErrorCode
   * @param string $_ErrorMsg
   */
  public function HandleError($_ErrorCode, $_ErrorMsg)
  { }

  /**
   * Filters to apply before the validate call
   *
   */
  public function BeforeFilters()
  { }

  /**
   * Filters to apply after the Display call
   *
   */
  public function AfterFilters()
  { }

  /**
   * Has there been a redirect?
   *
   * @return boolean
   */
  public function IsRedirected()
  {
    return $this->_redirected;
  }

  /**
   * Execute a redirect
   *
   * @param string $module
   * @param string $action
   */
  public function Redirect($module, $action, array $params = array())
  {
    $this->_redirected = true;
    self::$ROUTER->ExecuteRoute($module, $action, $params);
  }

}

?>
